<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>sin(1/x) 振荡间断点动态演示</title>
    <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }
        
        body {
            background: linear-gradient(135deg, #1a2a6c, #b21f1f, #fdbb2d);
            color: white;
            min-height: 100vh;
            padding: 20px;
        }
        
        .container {
            max-width: 1200px;
            margin: 0 auto;
            background: rgba(0, 0, 0, 0.7);
            border-radius: 15px;
            padding: 30px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
        }
        
        header {
            text-align: center;
            margin-bottom: 40px;
            padding-bottom: 20px;
            border-bottom: 2px solid rgba(255, 255, 255, 0.2);
        }
        
        h1 {
            font-size: 2.5rem;
            margin-bottom: 15px;
            color: #fdbb2d;
        }
        
        .subtitle {
            font-size: 1.2rem;
            opacity: 0.9;
            max-width: 800px;
            margin: 0 auto;
            line-height: 1.6;
        }
        
        .visualization-section {
            margin-bottom: 40px;
            padding: 25px;
            background: rgba(255, 255, 255, 0.1);
            border-radius: 10px;
        }
        
        h2 {
            font-size: 1.8rem;
            margin-bottom: 20px;
            color: #4dc9f6;
        }
        
        .graph-container {
            position: relative;
            height: 400px;
            margin: 20px 0;
            background: rgba(255, 255, 255, 0.05);
            border-radius: 8px;
            padding: 15px;
        }
        
        .controls {
            display: flex;
            flex-wrap: wrap;
            gap: 15px;
            margin: 20px 0;
            padding: 15px;
            background: rgba(255, 255, 255, 0.1);
            border-radius: 8px;
        }
        
        .control-group {
            flex: 1;
            min-width: 200px;
        }
        
        label {
            display: block;
            margin-bottom: 8px;
            font-weight: 500;
        }
        
        input[type="range"] {
            width: 100%;
            margin-bottom: 5px;
        }
        
        .value-display {
            display: flex;
            justify-content: space-between;
            font-size: 0.9rem;
            opacity: 0.8;
        }
        
        button {
            background: #fdbb2d;
            color: #1a2a6c;
            border: none;
            padding: 10px 20px;
            border-radius: 5px;
            font-weight: bold;
            cursor: pointer;
            transition: all 0.3s;
            margin-right: 10px;
            margin-bottom: 10px;
        }
        
        button:hover {
            background: #ffcc44;
            transform: translateY(-2px);
        }
        
        .explanation {
            margin-top: 30px;
            padding: 20px;
            background: rgba(255, 255, 255, 0.1);
            border-radius: 8px;
            line-height: 1.6;
        }
        
        .math-expression {
            font-family: 'Cambria Math', serif;
            font-size: 1.4rem;
            text-align: center;
            margin: 15px 0;
            color: #fdbb2d;
        }
        
        .key-point {
            background: rgba(77, 201, 246, 0.2);
            padding: 12px;
            border-radius: 6px;
            margin: 10px 0;
            border-left: 3px solid #4dc9f6;
        }
        
        .point-title {
            font-weight: bold;
            color: #4dc9f6;
        }
        
        .oscillation-info {
            display: flex;
            flex-wrap: wrap;
            gap: 20px;
            margin-top: 20px;
        }
        
        .info-card {
            flex: 1;
            min-width: 250px;
            padding: 15px;
            background: rgba(255, 255, 255, 0.1);
            border-radius: 8px;
        }
        
        .info-title {
            font-size: 1.2rem;
            margin-bottom: 10px;
            color: #fdbb2d;
        }
        
        footer {
            text-align: center;
            margin-top: 40px;
            padding-top: 20px;
            border-top: 1px solid rgba(255, 255, 255, 0.2);
            font-size: 0.9rem;
            opacity: 0.7;
        }
        
        @media (max-width: 768px) {
            .controls {
                flex-direction: column;
            }
            
            h1 {
                font-size: 2rem;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <header>
            <h1>sin(1/x) 振荡间断点动态演示</h1>
            <p class="subtitle">探索函数在 x=0 附近的振荡行为，理解为什么该点是振荡间断点</p>
        </header>
        
        <section class="visualization-section">
            <h2>动态函数图像</h2>
            <div class="math-expression">f(x) = sin(1/x)</div>
            
            <div class="graph-container">
                <canvas id="oscillationChart"></canvas>
            </div>
            
            <div class="controls">
                <div class="control-group">
                    <label for="zoomRange">缩放级别:</label>
                    <input type="range" id="zoomRange" min="1" max="100" value="10">
                    <div class="value-display">
                        <span>宽视图</span>
                        <span>精细视图</span>
                    </div>
                </div>
                
                <div class="control-group">
                    <label for="speedRange">动画速度:</label>
                    <input type="range" id="speedRange" min="1" max="10" value="5">
                    <div class="value-display">
                        <span>慢</span>
                        <span>快</span>
                    </div>
                </div>
                
                <div class="control-group">
                    <label>控制:</label>
                    <div>
                        <button id="playPauseBtn">暂停动画</button>
                        <button id="resetBtn">重置视图</button>
                    </div>
                </div>
            </div>
            
            <div class="explanation">
                <p><strong>当前视图范围:</strong> x ∈ [-<span id="currentRange">0.5</span>, <span id="currentRange2">0.5</span>]</p>
                <p><strong>观察要点:</strong> 当 x 趋近于 0 时，函数值在 -1 和 1 之间无限次振荡，且振荡频率无限增加。</p>
            </div>
        </section>
        
        <section class="visualization-section">
            <h2>振荡频率分析</h2>
            
            <div class="oscillation-info">
                <div class="info-card">
                    <div class="info-title">为什么振荡？</div>
                    <p>当 x → 0 时，1/x → ∞，因此 sin(1/x) 的参数趋向无穷大，导致正弦函数在 -1 和 1 之间无限振荡。</p>
                </div>
                
                <div class="info-card">
                    <div class="info-title">为什么频率增加？</div>
                    <p>随着 x 趋近于 0，1/x 的变化率急剧增加，导致 sin(1/x) 的振荡频率无限增大。</p>
                </div>
                
                <div class="info-card">
                    <div class="info-title">极限不存在</div>
                    <p>由于函数在 x=0 附近无限振荡，不趋近于任何固定值，因此极限 lim<sub>x→0</sub> sin(1/x) 不存在。</p>
                </div>
            </div>
            
            <div class="key-point">
                <div class="point-title">振荡间断点的定义：</div>
                <p>如果函数在某点的邻域内无限振荡，且在该点的极限不存在，则该点称为振荡间断点。</p>
            </div>
            
            <div class="key-point">
                <div class="point-title">与可去间断点的区别：</div>
                <p>可去间断点的极限存在但函数值未定义或不等于极限值，而振荡间断点的极限根本不存在。</p>
            </div>
        </section>
        
        <section class="visualization-section">
            <h2>数学分析</h2>
            
            <div class="math-expression">令 t = 1/x，则当 x → 0 时，t → ∞</div>
            <div class="math-expression">f(x) = sin(1/x) = sin(t)，其中 t → ∞</div>
            
            <div class="key-point">
                <div class="point-title">振荡序列：</div>
                <p>考虑序列 xₙ = 1/(nπ)，则 f(xₙ) = sin(nπ) = 0</p>
                <p>考虑序列 xₙ = 2/[(2n+1)π]，则 f(xₙ) = sin[(2n+1)π/2] = ±1</p>
                <p>这两个序列都收敛到 0，但函数值分别收敛到 0 和 ±1，因此极限不存在。</p>
            </div>
            
            <div class="key-point">
                <div class="point-title">可视化理解：</div>
                <p>使用上方的动态图表，放大 x=0 附近区域，观察函数如何无限次穿过 y=0 和达到极值 y=±1。</p>
            </div>
        </section>
        
        <footer>
            <p>振荡间断点动态演示 | 数学分析可视化工具</p>
        </footer>
    </div>

    <script>
        // 初始化图表
        const ctx = document.getElementById('oscillationChart').getContext('2d');
        let chart;
        let animationId;
        let isPlaying = true;
        let phase = 0;
        
        // 创建图表
        function createChart(zoomLevel = 10) {
            const range = 1 / zoomLevel;
            
            if (chart) {
                chart.destroy();
            }
            
            // 生成数据点
            const data = [];
            const pointCount = 2000; // 增加点数以显示更多细节
            
            for (let i = 0; i < pointCount; i++) {
                const x = -range + (2 * range * i) / (pointCount - 1);
                if (Math.abs(x) > 0.0001) { // 避免除以零
                    const y = Math.sin(1/x + phase);
                    data.push({x: x, y: y});
                }
            }
            
            chart = new Chart(ctx, {
                type: 'scatter',
                data: {
                    datasets: [{
                        label: 'sin(1/x)',
                        data: data,
                        borderColor: '#4dc9f6',
                        backgroundColor: 'rgba(77, 201, 246, 0.1)',
                        borderWidth: 1.5,
                        showLine: true,
                        pointRadius: 0,
                        tension: 0
                    }, {
                        label: 'y=0',
                        data: [{x: -range, y: 0}, {x: range, y: 0}],
                        borderColor: 'rgba(255, 255, 255, 0.5)',
                        borderWidth: 1,
                        borderDash: [5, 5],
                        showLine: true,
                        pointRadius: 0
                    }]
                },
                options: {
                    responsive: true,
                    maintainAspectRatio: false,
                    animation: false,
                    scales: {
                        x: {
                            type: 'linear',
                            position: 'bottom',
                            min: -range,
                            max: range,
                            title: {
                                display: true,
                                text: 'x',
                                color: 'white',
                                font: {
                                    size: 14,
                                    weight: 'bold'
                                }
                            },
                            grid: {
                                color: 'rgba(255, 255, 255, 0.1)'
                            },
                            ticks: {
                                color: 'white',
                                callback: function(value) {
                                    if (value === 0) return '0';
                                    return value.toExponential(1);
                                }
                            }
                        },
                        y: {
                            min: -1.2,
                            max: 1.2,
                            title: {
                                display: true,
                                text: 'f(x)',
                                color: 'white',
                                font: {
                                    size: 14,
                                    weight: 'bold'
                                }
                            },
                            grid: {
                                color: 'rgba(255, 255, 255, 0.1)'
                            },
                            ticks: {
                                color: 'white'
                            }
                        }
                    },
                    plugins: {
                        legend: {
                            labels: {
                                color: 'white'
                            }
                        },
                        tooltip: {
                            mode: 'index',
                            intersect: false,
                            callbacks: {
                                label: function(context) {
                                    let label = context.dataset.label || '';
                                    if (label) {
                                        label += ': ';
                                    }
                                    if (context.parsed.y !== null) {
                                        label += `(${context.parsed.x.toExponential(3)}, ${context.parsed.y.toFixed(3)})`;
                                    }
                                    return label;
                                }
                            }
                        }
                    }
                }
            });
            
            // 更新范围显示
            document.getElementById('currentRange').textContent = range.toFixed(3);
            document.getElementById('currentRange2').textContent = range.toFixed(3);
        }
        
        // 动画函数
        function animate() {
            if (!isPlaying) return;
            
            phase += 0.05 * (parseInt(document.getElementById('speedRange').value) / 5);
            const zoomLevel = parseInt(document.getElementById('zoomRange').value);
            createChart(zoomLevel);
            
            animationId = requestAnimationFrame(animate);
        }
        
        // 事件监听
        document.getElementById('zoomRange').addEventListener('input', function() {
            if (!isPlaying) {
                const zoomLevel = parseInt(this.value);
                createChart(zoomLevel);
            }
        });
        
        document.getElementById('playPauseBtn').addEventListener('click', function() {
            isPlaying = !isPlaying;
            this.textContent = isPlaying ? '暂停动画' : '播放动画';
            
            if (isPlaying) {
                animate();
            } else {
                cancelAnimationFrame(animationId);
            }
        });
        
        document.getElementById('resetBtn').addEventListener('click', function() {
            document.getElementById('zoomRange').value = 10;
            document.getElementById('speedRange').value = 5;
            phase = 0;
            createChart(10);
        });
        
        // 初始化
        document.addEventListener('DOMContentLoaded', function() {
            createChart(10);
            animate();
        });
    </script>
</body>
</html>